package Operation;

import demo1.Book;
import demo1.BookList;

import java.util.Scanner;

public class BorrowedOperation implements IOPeration {
    public void work(BookList bookList){
        System.out.println("借阅图书！");
        System.out.println("请输入书名！");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book2 = bookList.getBook(i);
            if(book2.getName().equals(name)){
                if(!book2.isBorrowed()){
                    book2.setBorrowed(true);
                    System.out.println("已借出！");
                }else {
                    System.out.println("已经被借走了！");
                }
                return;
            }
        }
        System.out.println("没有这本书！");
    }
}
